import { Injectable } from '@nestjs/common'
import { OssService } from '../oss/oss.service'
import { UnauthorizedException } from '@nestjs/common'

@Injectable()
export class FileService {
  constructor(private readonly ossService: OssService) {}

  // 上传照片
  async uploadImage(file: any): Promise<any> {
    try {
      const ossUrl = await this.ossService.putOssFile(
        `/image/${file.originalname}`,
        `D:/oss/image/${file.originalname}`,
      )
      return ossUrl
    } catch (error) {
      throw new UnauthorizedException(error)
    }
  }
}
